﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CluelessServer
{
    public class Board
    {
        private LinkedList<Room> rooms;

        public Board()
        {
            rooms = new LinkedList<Room>();

            rooms.AddLast(new Room("Study", RoomType.Room));
            rooms.AddLast(new Room("Study To Hall", RoomType.Hallway));
            rooms.AddLast(new Room("Hall", RoomType.Room));
            rooms.AddLast(new Room("Hall To Lounge", RoomType.Hallway));
            rooms.AddLast(new Room("Lounge", RoomType.Room));
            rooms.AddLast(new Room("Lounge To Dining Room", RoomType.Hallway));
            rooms.AddLast(new Room("Dining Room", RoomType.Room));
            rooms.AddLast(new Room("Dining Room To Kitchen", RoomType.Hallway));
            rooms.AddLast(new Room("Kitchen", RoomType.Room));
            rooms.AddLast(new Room("Kitchen To Ballroom", RoomType.Hallway));
            rooms.AddLast(new Room("Ballroom", RoomType.Room));
            rooms.AddLast(new Room("Ballroom To Conservatory", RoomType.Hallway));
            rooms.AddLast(new Room("Conservatory", RoomType.Room));
            rooms.AddLast(new Room("Conservatory To Library", RoomType.Hallway));
            rooms.AddLast(new Room("Library", RoomType.Room));
            rooms.AddLast(new Room("Library To Study", RoomType.Hallway));
            rooms.AddLast(new Room("Billard Room", RoomType.Room));
            rooms.AddLast(new Room("Library To Billard Room", RoomType.Hallway));
            rooms.AddLast(new Room("Hall To Billard Room", RoomType.Hallway));
            rooms.AddLast(new Room("Dining Room To Billard Room", RoomType.Hallway));
            rooms.AddLast(new Room("Ballroom To Billard Room", RoomType.Hallway));


            Room currRoom = GetRoom("Study");
            currRoom.AddNeighbor(GetRoom("Study To Hall"));
            currRoom.AddNeighbor(GetRoom("Library To Study"));
            currRoom.AddNeighbor(GetRoom("Kitchen"));

            currRoom = GetRoom("Study To Hall");
            currRoom.AddNeighbor(GetRoom("Hall"));
            currRoom.AddNeighbor(GetRoom("Study"));

            currRoom = GetRoom("Hall");
            currRoom.AddNeighbor(GetRoom("Study To Hall"));
            currRoom.AddNeighbor(GetRoom("Hall To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Hall To Lounge"));

            currRoom = GetRoom("Hall To Lounge");
            currRoom.AddNeighbor(GetRoom("Hall"));
            currRoom.AddNeighbor(GetRoom("Lounge"));

            currRoom = GetRoom("Lounge");
            currRoom.AddNeighbor(GetRoom("Hall To Lounge"));
            currRoom.AddNeighbor(GetRoom("Lounge To Dining Room"));
            currRoom.AddNeighbor(GetRoom("Conservatory"));

            currRoom = GetRoom("Lounge To Dining Room");
            currRoom.AddNeighbor(GetRoom("Lounge"));
            currRoom.AddNeighbor(GetRoom("Dining Room"));

            currRoom = GetRoom("Dining Room");
            currRoom.AddNeighbor(GetRoom("Lounge To Dining Room"));
            currRoom.AddNeighbor(GetRoom("Dining Room To Kitchen"));
            currRoom.AddNeighbor(GetRoom("Dining Room To Billard Room"));

            currRoom = GetRoom("Dining Room To Kitchen");
            currRoom.AddNeighbor(GetRoom("Dining Room"));
            currRoom.AddNeighbor(GetRoom("Kitchen"));

            currRoom = GetRoom("Kitchen");
            currRoom.AddNeighbor(GetRoom("Dining Room To Kitchen"));
            currRoom.AddNeighbor(GetRoom("Kitchen To Ballroom"));
            currRoom.AddNeighbor(GetRoom("Study"));

            currRoom = GetRoom("Kitchen To Ballroom");
            currRoom.AddNeighbor(GetRoom("Kitchen"));
            currRoom.AddNeighbor(GetRoom("Ballroom"));

            currRoom = GetRoom("Ballroom");
            currRoom.AddNeighbor(GetRoom("Kitchen To Ballroom"));
            currRoom.AddNeighbor(GetRoom("Ballroom To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Ballroom To Conservatory"));

            currRoom = GetRoom("Ballroom To Conservatory");
            currRoom.AddNeighbor(GetRoom("Ballroom"));
            currRoom.AddNeighbor(GetRoom("Conservatory"));

            currRoom = GetRoom("Conservatory");
            currRoom.AddNeighbor(GetRoom("Ballroom To Conservatory"));
            currRoom.AddNeighbor(GetRoom("Conservatory To Library"));
            currRoom.AddNeighbor(GetRoom("Lounge"));

            currRoom = GetRoom("Conservatory To Library");
            currRoom.AddNeighbor(GetRoom("Conservatory"));
            currRoom.AddNeighbor(GetRoom("Library"));

            currRoom = GetRoom("Library");
            currRoom.AddNeighbor(GetRoom("Conservatory To Library"));
            currRoom.AddNeighbor(GetRoom("Library To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Library To Study"));

            currRoom = GetRoom("Library To Study");
            currRoom.AddNeighbor(GetRoom("Library"));
            currRoom.AddNeighbor(GetRoom("Study"));

            currRoom = GetRoom("Hall To Billard Room");
            currRoom.AddNeighbor(GetRoom("Hall"));
            currRoom.AddNeighbor(GetRoom("Billard Room"));

            currRoom = GetRoom("Dining Room To Billard Room");
            currRoom.AddNeighbor(GetRoom("Dining Room"));
            currRoom.AddNeighbor(GetRoom("Billard Room"));

            currRoom = GetRoom("Ballroom To Billard Room");
            currRoom.AddNeighbor(GetRoom("Ballroom"));
            currRoom.AddNeighbor(GetRoom("Billard Room"));

            currRoom = GetRoom("Library To Billard Room");
            currRoom.AddNeighbor(GetRoom("Library"));
            currRoom.AddNeighbor(GetRoom("Billard Room"));

            currRoom = GetRoom("Billard Room");
            currRoom.AddNeighbor(GetRoom("Library To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Ballroom To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Dining Room To Billard Room"));
            currRoom.AddNeighbor(GetRoom("Hall To Billard Room"));

        }

        public LinkedList<Room> Rooms
        {
            get
            {
                return rooms;
            }
            set
            {
                rooms = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Room GetRoom(String name)
        {
            for (int i = 0; i < rooms.Count; i++)
            {

                if (String.Compare(rooms.ElementAt(i).Name, name) == 0)
                    return rooms.ElementAt(i);
            }

            throw new Exception("Failed to find the expected room! \"" + name + "\"  RoomList.GetRoom");
        }

    }
}
